package com.yidian.service.impl;

import com.yidian.common.entity.Result;
import com.yidian.entity.Article;
import com.yidian.entity.ArticleExample;
import com.yidian.entity.ArticleWithBLOBs;
import com.yidian.mapper.ArticleChannelMapper;
import com.yidian.mapper.ArticleMapper;
import com.yidian.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ArticleServiceImpl implements ArticleService {

    @Autowired
    private ArticleMapper articleMapper;
    @Autowired
    private ArticleChannelMapper articleChannelMapper;


    /**
     * 根据文章id获取文章详情（获取文章详情）
     * @param articleId
     * @return
     */
    @Override
    public Article selectArticleById(Long articleId) {
        return articleMapper.selectArticleById(articleId);
    }

    /**
     * 根据频道id查询下面所有的文章(获取频道的文章列表)
     * @param channelId
     * @return
     */
    @Override
    public List<Article> selectAllArticleByChannelId(long channelId) {
        return articleChannelMapper.selectAllArticleByChannelId(channelId);
    }

    /**
     * 所有的文章(获取频道的文章列表)
     * @return
     */
    @Override
    public List<Article> selectAllArticle() {
        return articleChannelMapper.selectAllArticle();
    }

    /**
     * 根据文章id让收藏字段加一（收藏文章)
     * @param articleId
     * @return
     */
    @Override
    public void updateArticleCollectAddCountByArticleId(Long articleId) {
        articleMapper.updateArticleCollectAddCountByArticleId(articleId);
    }

    /**
     * 根据文章id让收藏字段减一（取消收藏文章）
     * @param articleId
     * @return
     */
    @Override
    public void updateArticleCollectSubtractCountByArticleId(Long articleId) {
        articleMapper.updateArticleCollectSubtractCountByArticleId(articleId);
    }

    /**
     * 根据文章id让点赞字段加一（点赞文章）
     * @param articleId
     * @return
     */
    @Override
    public void updateArticleLikeAddCountByArticleId(Long articleId) {
        articleMapper.updateArticleLikeAddCountByArticleId(articleId);
    }

    /**
     * 根据文章id让点赞字段减一（取消点赞文章）
     * @param articleId
     * @return
     */
    @Override
    public void updateArticleLikeSubtractCountByArticleId(Long articleId) {
        articleMapper.updateArticleLikeSubtractCountByArticleId(articleId);
    }

    /**
     * 文章搜索
     *
     * @param keyword
     * @return
     */
    @Override
    public List<Article> search(String keyword) {
        return articleMapper.search(keyword);
    }


    /**
     * 查看所有文章
     */
    @Override
    public List<Article> selectArticle() {
        return articleMapper.selectArticle();
    }


}
